package com.mzj.saas.rent;

import com.alibaba.cola.statemachine.StateMachine;
import com.alibaba.cola.statemachine.StateMachineFactory;
import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.orderStateMachine.Event;
import com.haixiaoke.saas.repository.orderStateMachine.OrderStateEnum;
import com.haixiaoke.saas.repository.orderStateMachine.orderContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test/state/machine")
public class TestStateMachineController {

    @GetMapping
    public AjaxResult test() {
        StateMachine<OrderStateEnum, Event, orderContext> stateMachine = StateMachineFactory.get("orderStateMachineId");
        orderContext context = new orderContext();
        // 入住
        OrderStateEnum state = stateMachine.fireEvent(OrderStateEnum.ORDER_STATE_UN_PAYMENT, Event.CHECK_IN, context);
        System.out.println(state.equals(OrderStateEnum.ORDER_STATE_CHECK_IN));
        return AjaxResult.success();
    }


}
